package org.jeecg.modules.app.order.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.ApiLogin;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.app.order.service.AppPowerBankOrderService;
import org.jeecg.modules.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * @BelongsProject: jeecg-boot-parent  租借订单
 * @BelongsPackage: org.jeecg.modules.app.order.controller
 * @Author: mi
 * @CreateTime: 2024-07-27 14:13
 * @Description:
 */
@CrossOrigin
@Api(tags = "APP运营端租借订单相关接口（首页）")
@RestController
@RequestMapping("/api/appPowerBankOrder")
public class AppPowerBankOrderController {

    @Autowired
    private AppPowerBankOrderService appPowerBankOrderService;


    //首页租借订单折线图  getIncomeLineChart
    @ApiLogin
    @ApiOperation("APP运营端-首页租借收益订单折线图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cycleTime", value = "时间周期近 （1 、30天 2、 6个月)", required = true),
    })
    @GetMapping("/getIncomeLineChart")
    public Result<?>getIncomeLineChart(HttpServletRequest request, Integer cycleTime){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象
        if (oConvertUtils.isEmpty(cycleTime))return Result.error_599("时间周期不可为空");
        //判断用户身份 是组长 还是组员 （组织部门）
        return appPowerBankOrderService.getIncomeLineChart(user,cycleTime);
    }

    @ApiLogin
    @ApiOperation(value = "APP运营端-首页租借订单统计数量(折线图默认7天)", notes = "统计返回type值为1今日下单数 2今日租借订单收款数 3本月收款数 4 硬件破损率 ")
    @GetMapping("/getAppPowerBankOrderQuantity")
    public Result<?>getAppPowerBankOrderQuantity(HttpServletRequest request){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象
        return  appPowerBankOrderService.getAppPowerBankOrderQuantity(user);
    }






    @ApiLogin
    @ApiOperation(value = "APP运营端-首页门店统计(折线图默认7天)", notes = "统计返回type值为1柜机门店数 2、0收益门店数、3 新铺门店数 4 撤机门店数 5净增门店数 ")
    @GetMapping("/getHomeShopQuantity")
    public Result<?>getHomeShopQuantity(HttpServletRequest request){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象
        return  appPowerBankOrderService.getHomeShopQuantity(user);
    }


















    //收益页-2级页面   APP运营端-收益页-2级页面
    @ApiLogin
    @ApiOperation(value = "APP运营端-收益页-2级页面(包含门店设备收益)", notes = "APP运营端-收益页-2级页面    \"shopList\": [\n" +
            "      {\n" +
            "        \"shopBd\": \"jfz|19876543213\",\n" +
            "        \"mapValueList\": [\n" +
            "          {\n" +
            "            \"quantity\": \"设备订单数\",\n" +
            "            \"treasureQuantity\": \"单宝收益/订单\",\n" +
            "            \"orderPrice\": \"设备收益\",\n" +
            "            \"incomeQuantity\": \"单柜收益/订单\",\n" +
            "            \"categoryName\": \"十二孔柜机\",\n" +
            "            \"mac\": \"MAC_6178231892315433\"\n" +
            "          }\n" +
            "        ],\n" +
            "        \"shopName\": \"联安酒店公寓（联安大厦）\",\n" +
            "        \"id\": \"1815631384430379010\",\n" +
            "        \"shopAddress\": \"联安现代城\"\n" +
            "      }\n" +
            "    ],")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mark", value = "标记 （1 、小组id 2、业务员id)组员只能看自己的 组长可以看整个小组或单独业务员的 ", required = false),
            @ApiImplicitParam(name = "userId", value = "业务id(标记传1传小组id、标记2 传业务员id   )", required = false),
            @ApiImplicitParam(name = "type", value = "时间类型（1今日、2昨日、3本周、4本月）", required = true),

            @ApiImplicitParam(name = "categoryId", value = "设备类型id", required = false),
    })
    @GetMapping("/getTwoIncomeOrder")
    public Result<?>getTwoIncomeOrder(HttpServletRequest request,Integer mark,String userId,Integer type,String categoryId){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象

        if (oConvertUtils.isEmpty(type)){
            type=1;//不传默认查今日
        }


        if (oConvertUtils.isEmpty(mark)){//当不传标记时 默认查询
            if (user.getIsLeaders().equals("1")){//用户是组长身份
                mark=1;
                userId=user.getGroupIds();//小组id
            }else {//组员
                mark=2;
                userId=user.getId();//业务员id
            }
        }
        return   appPowerBankOrderService.getTwoIncomeOrder(user, mark, userId, type,categoryId);
    }



    //APP运营端-首页门店-2级页面(0收益门店数据)  getZeroShopData
    @ApiLogin
    @ApiOperation(value = "APP运营端-门店-2级页面(0收益门店数据)", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mark", value = "标记 （1 、小组id 2、业务员id)组员只能看自己的 组长可以看整个小组或单独业务员的 ", required = false),
            @ApiImplicitParam(name = "userId", value = "业务id(标记传1传小组id、标记2 传业务员id   )", required = false),
            @ApiImplicitParam(name = "cancellation", value = "排序 1 正序 2 倒序", required = false),
    })
    @GetMapping("/getZeroShopData")
    public Result<?>getZeroShopData(HttpServletRequest request,Integer mark,String userId,Integer cancellation){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象
        if (oConvertUtils.isEmpty(mark)){//当不传标记时 默认查询
            if (user.getIsLeaders().equals("1")){//用户是组长身份
                mark=1;
                userId=user.getGroupIds();//小组id
            }else {//组员
                mark=2;
                userId=user.getId();//业务员id
            }
        }
        if (oConvertUtils.isEmpty(cancellation))cancellation=1;
        return  appPowerBankOrderService.getZeroShopData(user, mark, userId, cancellation);

    }

    //APP运营端-门店-2级页面(新增店铺)getAddShopData
    @ApiLogin
    @ApiOperation(value = "APP运营端-门店-2级页面(新增店铺)", notes = "APP运营端-门店-2级页面(新增店铺)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mark", value = "标记 （1 、小组id 2、业务员id)组员只能看自己的 组长可以看整个小组或单独业务员的 ", required = false),
            @ApiImplicitParam(name = "userId", value = "业务id(标记传1传小组id、标记2 传业务员id   )", required = false),
            @ApiImplicitParam(name = "type", value = "时间类型（1今日、2昨日、3本周、4本月）", required = true),
    })
    @GetMapping("/getAddShopData")
    public Result<?>getAddShopData(HttpServletRequest request,Integer mark,String userId,Integer type){
        if (oConvertUtils.isEmpty(type))type=1;

        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象

        if (oConvertUtils.isEmpty(mark)){//当不传标记时 默认查询
            if (user.getIsLeaders().equals("1")){//用户是组长身份
                mark=1;
                userId=user.getGroupIds();//小组id
            }else {//组员
                mark=2;
                userId=user.getId();//业务员id
            }
        }
//        Result<?>getAddShopData( SysUser user,Integer mark,String userId,Integer type)
        return  appPowerBankOrderService.getAddShopData(user, mark, userId, type);
    }


    // getWeaningShopData  APP运营端-门店-2级页面(撤机门店)

    @ApiLogin
    @ApiOperation(value = "APP运营端-门店-2级页面(撤机门店)", notes = "APP运营端-门店-2级页面(撤机门店)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mark", value = "标记 （1 、小组id 2、业务员id)组员只能看自己的 组长可以看整个小组或单独业务员的 ", required = false),
            @ApiImplicitParam(name = "userId", value = "业务id(标记传1传小组id、标记2 传业务员id   )", required = false),
            @ApiImplicitParam(name = "type", value = "时间类型（2昨日、3本周、4本月）", required = true),
    })
    @GetMapping("/getWeaningShopData")
    public Result<?>getWeaningShopData(HttpServletRequest request,Integer mark,String userId,Integer type)throws ParseException {
        if (oConvertUtils.isEmpty(type))type=2;
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象
        if (oConvertUtils.isEmpty(mark)){//当不传标记时 默认查询
            if (user.getIsLeaders().equals("1")){//用户是组长身份
                mark=1;
                userId=user.getGroupIds();//小组id
            }else {//组员
                mark=2;
                userId=user.getId();//业务员id
            }
        }

        return appPowerBankOrderService.getWeaningShopData(user, mark, userId, type);

    }














    //收益页-2级页面-门店收益- 门店设备收益  APP运营端-收益页-2级页面
    @ApiLogin
    @ApiOperation(value = "APP运营端-收益页-2级页面-门店收益", notes = "APP运营端-收益页-2级页面-门店收益(shopType 0 代表 无差异 1 上涨  2下降)-门店设备收益")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mark", value = "标记 （1 、小组id 2、业务员id)组员只能看自己的 组长可以看整个小组或单独业务员的 ", required = false),
            @ApiImplicitParam(name = "userId", value = "业务id(标记传1传小组id、标记2 传业务员id)", required = false),

    })
    @GetMapping("/getTwoShopIncomeOrder")
    public Result<?>getTwoShopIncomeOrder(HttpServletRequest request,Integer mark,String userId){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象
        if (oConvertUtils.isEmpty(mark)){
            if (user.getIsLeaders().equals("1")){
                userId=user.getGroupIds();
                mark=1;
            }else {
                mark=2;
                userId=user.getId();//业务员id
            }
        }
            return appPowerBankOrderService.getTwoShopIncomeOrder(user, mark, userId);


    }

    //硬件问题2级页面



    @ApiLogin
    @ApiOperation(value = "APP运营端-硬件问题2级页面", notes = "APP运营端-硬件问题2级页面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopName", value = "门店名称检索 ", required = false),
            @ApiImplicitParam(name = "mark", value = "标记 （1 、小组id 2、业务员id)组员只能看自己的 组长可以看整个小组或单独业务员的 ", required = false),
            @ApiImplicitParam(name = "userId", value = "业务id(标记传1传小组id、标记2 传业务员id)", required = false),
            @ApiImplicitParam(name = "type", value = "时间类型（1今日、2昨日、3 近7天、4本月）", required = true),
            @ApiImplicitParam(name = "categoryId", value = "设备类型id", required = false),

            @ApiImplicitParam(name = "cancellation", value = "取消数 1 正序 2 倒序 取消率 3正序 4 倒序", required = false),

    })
    @GetMapping("/getTwoProblemOrderQuantity")
    public Result<?>getTwoProblemOrderQuantity(HttpServletRequest request,String shopName ,Integer mark,String userId,Integer type,String categoryId,Integer cancellation){
        SysUser user=new ObjectMapper().convertValue(request.getAttribute("sysUser"),SysUser.class);//转对象 用户登陆对象

        if (oConvertUtils.isEmpty(type)){
            type=1;
        }
        if (oConvertUtils.isEmpty(mark)){
            if (user.getIsLeaders().equals("1")){
                userId=user.getGroupIds();
                mark=1;
            }else {
                mark=2;
                userId=user.getId();//业务员id
            }
        }
        if (oConvertUtils.isEmpty(cancellation)){
            cancellation=1;
        }

        return appPowerBankOrderService.getTwoProblemOrderQuantity(user, shopName, mark, userId, type, categoryId, cancellation);

    }




}
